import Vue from 'vue'
import Vuex from 'vuex'
import { getItem, setItem } from '../utiles/storage'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 定义用户的token
    // user: JSON.parse(localStorage.getItem('toutiao-user'))
    user: getItem('toutiao_user') || {}
  },
  mutations: {
    // 设置token
    setUser(state, data) {
      // 设置给state
      state.user = data
      // 存储到本地
      // localStorage.setItem('toutiao-user', JSON.stringify(data))
      setItem('toutiao_user', data)
    }
  },
  // 建立快捷访问
  getters: {
    token: state => state.user.token
  },
  actions: {
  },
  modules: {
  }
})
